﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Autofac;
using Autofac.Integration.Mvc;
using TpWeb.Dal;

namespace TpWeb
{
    public class MvcApplication : System.Web.HttpApplication
    {
        public static IContainer container;
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);



            var builder = new ContainerBuilder();

            builder.RegisterModule(new DalModule());
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            // Register MVC specific abstractions (HttpRequestBase,HttpResponceBase etc)
            builder.RegisterModule(new AutofacWebTypesModule());

            container = builder.Build();

             //GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            //            DependencyResolver.SetResolver(new AutofacWebApiDependencyResolver(container));
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
    }
}
